package com.hospital.doctor.controller;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.hospital.doctor.pojo.Round;
import com.hospital.doctor.service.PatientService;
import com.hospital.doctor.service.RoundService;
import com.hospital.doctor.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/round")
@CrossOrigin
public class RoundController {

    @Autowired
    private RoundService roundService;

    @Autowired
    private PatientService patientService;

    @RequestMapping("/selectAllByPid/{id}")
    public Map<String,Object> selectAllByPid(@PathVariable("id") int pId){
        Map<String,Object> map = new HashMap<>();
        map.put("round",roundService.selectAllByPid(pId));
        map.put("patient",patientService.selectById(pId));
        return map;
        
    }

    @RequestMapping("/insertRound")
    public Map<String,Object> insertRound(@RequestBody Round round, HttpServletRequest request){

        DecodedJWT token = JWTUtils.verify(request.getHeader("token"));
        round.setdId(Integer.valueOf(token.getClaim("id").asString()));
        Map<String,Object> map = new HashMap<>();
        map.put("msg",roundService.insertRound(round));
        return map;
    }


}
